﻿#ifndef MAINDEAL_H
#define MAINDEAL_H

#include "QTimer"
#include "param.h"
#include "udputils.h"
#include "utility.h"

#include <QBitArray>
#include <QDebug>
#include <QMap>
#include <QMetaEnum>
#include <QObject>
#include <QThread>
#include <QtNetwork>

struct AgvState;
class Agvhardware;
#include "agvhardware.h"

class Navigator;
#include "navigator.h"

class Maindeal : public QObject {
    Q_OBJECT
public:
    explicit Maindeal( int argc, char** argv, QObject* parent = nullptr );
    ~Maindeal();
    Agvhardware* agvhardware() const;
    Navigator*   navigator() const;

    void sysRecvData( const QByteArray& data );
    void chargeRecvData( const QByteArray& data );
    void AgvToSystemOrder();
    void setCancelMission( bool sw );
    bool isAllowExecuteForklift();
    bool isAllowExitMachine();
    int  getSysLine() const;

private:
    Agvhardware* agvhardware_   = nullptr;
    Navigator*   navigator_     = nullptr;
    bool         is_order_error = false;  //收到的命令是否错误执行
    char         sys_recv_size = 8, charge_recv_size = 6;
    int          sys_line = 0;  //线别参数
    int          argc;
    char**       argv;
    bool         is_need_cancel_mission = false;  // UPDATE 2022.06.06 取消任务

    UDPUtils* udp;

    QThread* udpThread;
signals:
    void sigSendSystemOrder( const QByteArray&, const QString& );
    void sigRecvSystemOrder( const QByteArray&, const QString& );
    void sigSendChargeOrder( const QByteArray&, const QString& );
    void sigSendTips( const QString& );

public slots:
    void sltMaindealInit();
    void sltUdpRecvData( const QString& ip, const QByteArray& data );
    void sltTimeOut();
};

#endif  // MAINDEAL_H
